//
//  Notification.m
//  itaka
//
//  Created by Robert Soszynski on 1/18/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "Notification.h"

@implementation Notification
@synthesize title, message;

- (id) init {
    if (self = [super init])
    {
        UIApplication *app = [UIApplication sharedApplication];
        NSArray *oldNotifications         = [app scheduledLocalNotifications];
        
        if ([oldNotifications count] > 0) {
            [app cancelAllLocalNotifications];
        }
        
        notification = [[UILocalNotification alloc] init];
        
        title = @"Sign in";
        message = @"You have to sign in, before using the device.";
        
        notification.timeZone  = [NSTimeZone systemTimeZone];
        notification.repeatInterval = NSMinuteCalendarUnit;
        //notification.soundName = @"/System/Library/Audio/UISounds/alarm.caf";
        
        [self enable];
    }
    return self;
}

- (void) enable {
    NSDate *notificationDate = [NSDate dateWithTimeIntervalSinceNow:10];
    
    notification.fireDate  = notificationDate;
    notification.alertAction = title;
    notification.alertBody = message;
    
    UIApplication *app = [UIApplication sharedApplication];
    [app scheduleLocalNotification: notification];
    
    NSLog(@"Notification: On");
}

- (void) disable {
    UIApplication *app = [UIApplication sharedApplication];
    [app cancelLocalNotification: notification];
    
    NSLog(@"Notification: Off");
}

@end
